<%@page language="java" isELIgnored="false" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<jsp:directive.include file="/WEB-INF/sitemesh-decorators/include.jsp"/>
<fmt:setBundle basename="bundles.thesis-resources"/>
<html>
<head>
<title>Edit <fmt:message key="thesis.title"/> <fmt:message key="thesiscommittee.title"/></title>
<script type="text/javascript">
$(function() {
	var facultyList = '${facultyList}';
	var facultyStr = facultyList.substring(facultyList.indexOf('{')+1,facultyList.indexOf('}'));
	
	facultyStr = facultyStr.replace(/=/g,":");
	var facultyArr=facultyStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<facultyArr.length;i++){
		tempStr = facultyArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		tempArray[i]= tempStr;
	}
	
	$( "#thesiscommitteeChair").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var faculty = ui.item.value;
			getId(faculty,facultyArr,'thesiscommittee_facultyByChair');
			$("#thesiscommitteeChair").val(faculty);
		},
	});
	
	/*

	$( "#thesiscommitteeMember2").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,categoryArr,'thesiscommittee_facultyByCommitteeMember2');
			$("#thesiscommittee_thesisCommittee").val(cat);
		},
	});
	$( "#thesiscommitteeMember3").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,categoryArr,'thesiscommittee_facultyByCommitteeMember3');
			$("#thesiscommittee_thesisCommittee").val(cat);
		},
	});
	$( "#thesiscommitteeMember4").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,categoryArr,'thesiscommittee_facultyByCommitteeMember4');
			$("#thesiscommittee_thesisCommittee").val(cat);
		},
	});
	$( "#thesiscommitteeMember5").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,categoryArr,'thesiscommittee_facultyByCommitteeMember5');
			$("#thesiscommittee_thesisCommittee").val(cat);
		},
	});*/
	
});


$(function() {
	var facultyList = '${facultyList}';
	var facultyStr = facultyList.substring(facultyList.indexOf('{')+1,facultyList.indexOf('}'));
	
	facultyStr = facultyStr.replace(/=/g,":");
	//alert(facultyStr);
	var facultyArr=facultyStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<facultyArr.length;i++){
		tempStr = facultyArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		tempArray[i]= tempStr;
	}
	
	$( "#thesiscommitteeMember1").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,facultyArr,'thesiscommittee_facultyByCommitteeMember1');
			$("#thesiscommitteeMember1").val(cat);
		},
	});
});

$(function() {
	var facultyList = '${facultyList}';
	var facultyStr = facultyList.substring(facultyList.indexOf('{')+1,facultyList.indexOf('}'));
	
	facultyStr = facultyStr.replace(/=/g,":");
	//alert(facultyStr);
	var facultyArr=facultyStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<facultyArr.length;i++){
		tempStr = facultyArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		tempArray[i]= tempStr;
	}
	
	$( "#thesiscommitteeMember2").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,facultyArr,'thesiscommittee_facultyByCommitteeMember2');
			$("#thesiscommitteeMember2").val(cat);
		},
	});
});


$(function() {
	var facultyList = '${facultyList}';
	var facultyStr = facultyList.substring(facultyList.indexOf('{')+1,facultyList.indexOf('}'));
	
	facultyStr = facultyStr.replace(/=/g,":");
	//alert(facultyStr);
	var facultyArr=facultyStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<facultyArr.length;i++){
		tempStr = facultyArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		tempArray[i]= tempStr;
	}
	
	$( "#thesiscommitteeMember3").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,facultyArr,'thesiscommittee_facultyByCommitteeMember3');
			$("#thesiscommitteeMember3").val(cat);
		},
	});
});

$(function() {
	var facultyList = '${facultyList}';
	var facultyStr = facultyList.substring(facultyList.indexOf('{')+1,facultyList.indexOf('}'));
	
	facultyStr = facultyStr.replace(/=/g,":");
	//alert(facultyStr);
	var facultyArr=facultyStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<facultyArr.length;i++){
		tempStr = facultyArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		tempArray[i]= tempStr;
	}
	
	$( "#thesiscommitteeMember4").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,facultyArr,'thesiscommittee_facultyByCommitteeMember4');
			$("#thesiscommitteeMember4").val(cat);
		},
	});
});


$(function() {
	var facultyList = '${facultyList}';
	var facultyStr = facultyList.substring(facultyList.indexOf('{')+1,facultyList.indexOf('}'));
	
	facultyStr = facultyStr.replace(/=/g,":");
	//alert(facultyStr);
	var facultyArr=facultyStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<facultyArr.length;i++){
		tempStr = facultyArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		tempArray[i]= tempStr;
	}
	
	$( "#thesiscommitteeMember5").autocomplete({
		source: tempArray,
		select: function(e, ui) {
			var cat = ui.item.value;
			getId(cat,facultyArr,'thesiscommittee_facultyByCommitteeMember5');
			$("#thesiscommitteeMember5").val(cat);
		},
	});
});

function getId(str,arr,divId){
	var key = "";
	var value ="";
	var tempStr="";
	for(var i=0;i<arr.length;i++){
		tempStr = arr[i];
		tempStr = tempStr.replace(/^\s+|\s+$/g,'');
		key=tempStr.substring(0,tempStr.indexOf(":"));
		value = tempStr.substring(tempStr.indexOf(":")+1);
		if(value==str){
			$("#"+divId).val(key);
		}
	}
}	
</script>
</head>
<body>
<div id="contentarea">   
<script type="text/javascript">
$().ready(function() {
	$('#thesiscommitteeform').validate();
});
</script>   
	<div id="lb"><div id="rb"><div id="bb"><div id="blc">
	<div id="brc"><div id="tb"><div id="tlc"><div id="trc">
	<div id="content">
		<h1><%--<fmt:message key="navigation.edit"/> --%> <fmt:message key="thesiscommittee.title"/></h1>
		<div class="navitem"><a class="button" href="${pageContext.request.contextPath}/selectThesis?thesisIdKey=${thesis_thesisId}&"><span><img src="includes/images/icons/back.gif" /><fmt:message key="navigation.back"/></span></a></div>
		<form:form id="thesiscommitteeform" action="${pageContext.request.contextPath}/saveThesisThesiscommittees" method="POST" modelAttribute="thesiscommittee">
			<form:hidden id="thesiscommittee_thesisCommitteeId" path="thesisCommitteeId"/>
			<table cellpadding="0" cellspacing="0" id="viewTable">
				<tbody>
					<tr>
						<td class="label" valign="top">
							Thesis Committee Chair:
						</td>
						
						<td>
							<input type="text" id="thesiscommitteeChair" class="required"/>
							<form:hidden id="thesiscommittee_facultyByChair" path="facultyByChair"/>
						</td>
					</tr>
					<tr>
						<td class="label" valign="top">Committee Member 1:</td>
						<td>
						<input type="text" id="thesiscommitteeMember1"/>
						<form:hidden id="thesiscommittee_facultyByCommitteeMember1" path="facultyByCommitteeMember1"/>
						</td>
					</tr>

					<tr>
						<td class="label" valign="top">Committee Member 2:</td>
						<td>
						<input type="text" id="thesiscommitteeMember2" />
						<form:hidden id="thesiscommittee_facultyByCommitteeMember2"	path="facultyByCommitteeMember2"/>
						</td>
					</tr>

					<tr>
						<td class="label" valign="top">Committee Member 3:</td>
						<td>
						<input type="text" id="thesiscommitteeMember3" />
						<form:hidden id="thesiscommittee_facultyByCommitteeMember3"	path="facultyByCommitteeMember3"/></td>
					</tr>

					<tr>
						<td class="label" valign="top">Committee Member 4:</td>
						<td>
						<input type="text" id="thesiscommitteeMember4" />
						<form:hidden id="thesiscommittee_facultyByCommitteeMember4"	path="facultyByCommitteeMember4"/>
						</td>
					</tr>

					<tr>
						<td class="label" valign="top">Committee Member 5:</td>
						
						<td>
						<input type="text" id="thesiscommitteeMember5" />
						<form:hidden id="thesiscommittee_facultyByCommitteeMember5" path="facultyByCommitteeMember5" />
						</td>
					</tr>



				</tbody>
			</table>
			<span class="inputbutton"><input class="savebutton" id="save" type="submit" value="<fmt:message key="navigation.save"/>"/></span>
			<script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'save', event:'onclick'}));</script>
				<input type="hidden" name="thesis_thesisId" value="${thesis_thesisId}" >
				
				
				
				
				
				
		</form:form>
		<div class="clear">&nbsp;</div>
	</div>
	</div></div></div></div>
	</div></div></div></div>
</div>
</body>
</html>
<script type="text/javascript">
/* $(function() {
	
	var facultyList = '${facultyList}';
	alert(facultyList);
	var facultyStr = facultyList.substring(facultyList.indexOf('{')+1,facultyList.indexOf('}'));
	alert(facultyStr.replace(/=/g,":"));
	facultyStr = facultyStr.replace(/=/g,":");
	var facultyArr=facultyStr.split(',');
	for(var i=0;i<facultyArr.length;i++){
		alert(facultyArr[i]);
	}
	
	var tempStr1="";
	var tempStr2="";
	$( "#committeeChairData" ).autocomplete({
		source: facultyArr,
		select: function(e, ui) {
		//create formatted data
		var faculty = ui.item.value;
		tempStr1 = faculty.substring(faculty.indexOf(":")+1);
		
		tempStr2 = faculty.substring(0,faculty.indexOf(":"));
		alert(tempStr2);
		$("#committeeChairData").text(tempStr1);
		},
		close: function(event, ui) {
			
			$("#committeeChair").val(tempStr2);
		}
	});
}); */
</script>